# 守护: 我守护者你,你要是死了,我就跟你一起.
# 子进程对父进程可以进行守护.
# 生产者消费者模型会讲到.
from multiprocessing import Process
import time
import os

def task(name):

    print(f'{name} is running')
    print(f'子进程开始了:{os.getpid()}')
    time.sleep(50)


if __name__ == '__main__':

    p = Process(target=task,args=('怼哥',))
    p.daemon = True  # 将p子进程设置成守护进程,守护主进程,只要主进程结束,子进程无论执行与否,都马上结束.
    p.start()
    time.sleep(2)
    print(f'主进程开始了:{os.getpid()}')
